<template>
  <view class="ranking-container">
    <image class="ranking-bg" :src="getRankingBg"/>
    <text class="ranking-text" :class="{'text-white':ranking <= 3 }">{{ ranking }}</text>
  </view>
</template>

<script>
import ranking1 from "@/static/images/ranking-1.png"
import ranking2 from "@/static/images/ranking-2.png"
import ranking3 from "@/static/images/ranking-3.png"
import ranking_other from "@/static/images/ranking-other.png"


export default {
  name: "hot-ranking",
  props: {
    ranking: {
      type: Number,
      require: true
    }
  },
  data() {
    return {
      img: [ranking_other, ranking1, ranking2, ranking3]
    };
  },
//   当依赖值发生变化时，计算属性就会重新计算
  computed: {
    //每个计算属性都必须要有一个返回值
    getRankingBg() {

      if (this.ranking <= 3) {
        return this.img[this.ranking]
      }
      return this.img[0]

    }
  }
}
</script>

<style lang="scss" scoped>
.ranking-container {
  position: relative;
  text-align: center;
  width: 18px;
  height: 20px;

  .ranking-bg {
    width: 100%;
    height: 100%;
  }

  .ranking-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-55%, -55%);
    font-size: 12px;
    font-weight: bold;
    color: #333;
  }
  .text-white {
    color: white;
  }
}
</style>
